/**
 * Created by MDURAND on 08/12/2014.
 */

helloseriesApp.directive( 'hsCheckRolesEnable',  ['AuthService', function(AuthService) {
    return {
        restrict : 'A',
        link : function( scope, element, attrs) {

            function disableElement(){
                attrs.$set('disabled', 'disabled');
            }

            function enableElement(){
                element.removeAttr('disabled');
            }
            scope.$watch(
                function() {
                    return AuthService.getCurrentUser();
                },
                function () {
                    if (AuthService.isAuthenticated() &&  AuthService.getCurrentUser().role == 'ADMIN')
                    {
                        enableElement();
                    }
                    else {
                        disableElement()
                    }
                  }
            )


        }
    };
}]);

helloseriesApp.directive( 'hsCheckRolesShow',  ['AuthService', function(AuthService) {
    return {
        restrict: 'A',
        link: function (scope, element) {
            function showElement(){
                element.show();
            }

            function hideElement(){
                element.hide();
            }

            scope.$watch(
                function() {
                    return AuthService.getCurrentUser();
                },
                function () {
                    if (AuthService.isAuthenticated() &&   AuthService.getCurrentUser().role == 'ADMIN')
                    {
                        showElement();
                    }
                    else {
                        hideElement();
                    }
                 }
            )
        }
    };
}]);

helloseriesApp.directive( 'hsCheckRolesHide',  ['AuthService', function(AuthService) {
    return {
        restrict: 'A',
        link: function (scope, element) {
            function showElement(){
                element.show();
            }

            function hideElement(){
                element.hide();
            }

            scope.$watch(
                function() {
                    return AuthService.getCurrentUser();
                },
                function () {
                    if (AuthService.isAuthenticated() &&   AuthService.getCurrentUser().role == 'ADMIN')
                    {
                        hideElement();
                    }
                    else {
                        showElement();
                    }
                }
            )
        }
    };
}]);
